﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using KPWeb.Class;
using KPWeb.Data;
using KPWeb.Function;
using KPWeb.Reports;

namespace KPWeb.AnkietaOcenaPracownika
{
    public partial class ListaPracownikowAnkietaOcena : KPPage
    {
        //private short RokPlany
        //{

        //    get
        //    {
        //        if (ViewState["RokPlany"] == null)
        //            ViewState["RokPlany"] = DateTime.Now.Year;
        //        return short.Parse(ViewState["RokPlany"].ToString());
        //    }
        //    set
        //    {
        //        ViewState["RokPlany"] = value;

        //    }
        //}

        //Wykaz osób w jednostce do zmian danych 



        protected void Page_Load(object sender, EventArgs e)
        {
            Error1.Visible = false;

            if (!IsPostBack)
            {

                dGrupa.Items.Clear();
                dGrupa.Items.Add(new ListItem() { Text = Stale.wybierzGrupe, Value = "0" });
                foreach (vKP_JednostkiGrupy item in Model.GetGrupyDlaFirmy(int.Parse(Current.FirmaID)))
                {
                    dGrupa.Items.Add(new ListItem()
                    {
                        Text = item.GrupaOpis ,
                        Value = item.GrupaID.ToString()
                    });
                }
                dGrupa.SelectedIndex = 0;
               
                dYear.Items.Clear();
                foreach (short item in Kalendarz.GetYearGdzieWpisanoSwieta())
                {
                    this.dYear.Items.Add(item.ToString());
                }
                dYear.SelectedValue = DateTime.Now.Year.ToString();
                hJednostkaID.Value = hJednostkaID.Value = Model.GetJednostkaGlownaDlaJednostki(int.Parse(Current.JednostkaID)).ToString();
      
            }
        }

        protected void btnPlanyUrlopoweRoboczeClick(object sender, EventArgs e)
        {


            RaportyPDF.RaportPlanUrlopowyBarCodePDF(0, int.Parse(hJednostkaID.Value), int.Parse(dGrupa.SelectedValue), int.Parse(dYear.SelectedValue));




        }



        protected void btnPrzeslijDoKadrClick(object sender, EventArgs e)
        {

        }

        protected void podgladAnkietaOcenaClick(object sender, System.EventArgs e)
        {

            Server.Transfer("~/AnkietaOcenaPracownika/AnkietaMojaOcena.aspx?value=1");

        }
        protected void edycjaAnkietaOcenaClick(object sender, System.EventArgs e)
        {

            Server.Transfer("~/AnkietaOcenaPracownika/AnkietaMojaOcena.aspx?value=1");


        }

      

        protected void dGrupa_SelectedIndexChanged(object sender, EventArgs e)
        {
           // hGrupaID.Value = dGrupa.SelectedItem.Value;
        //    ListView1.DataBind();
        }
      
        
        protected void ListView1_ItemDataBound(object sender, ListViewItemEventArgs e)
        {
          
            string sTemp = ((Label)e.Item.FindControl("NazwiskoImie")).Text;
          
               ((Label)e.Item.FindControl("NazwiskoImie")).Text = FunctionGlobal.UppercaseFirstWords(sTemp);
          }
        protected void btnCofnijUClick(object sender, EventArgs e)
        {
           short yTemp= short.Parse(dYear.SelectedValue);


            if (NieobecnosciUrlopy.UpdatePlanyUrlopow( int.Parse(((Button)sender).CommandArgument.ToString()), yTemp, 1, 0) != 0)
                    {
                        Error1.Visible = true;
                        return;
                    }
                 
            if (NieobecnosciUrlopy.DeletePlanyUrlopowOkresy(int.Parse(((Button)sender).CommandArgument.ToString()), yTemp)!=0)
              {
                Error1.Visible = true;
                return;
            }
            this.ListView1.DataBind();
     
        }
    }
}